<template>
  <div class="bg-c-fff mb70 container min-height">
    <h2 class="box-title rel"><a href="#/index/role-manage">权限管理-角色管理</a> > 新增角色</h2>
    <form @submit.prevent="onSubmitClick">
      <ul>
        <li>
          <span>角色名称：</span>
          <input type="text" class="input-css input-w1" v-model="roleName">
        </li>
        <li>
          <span>是否可用：</span>
          <div class="dib">
            <input type="radio" id="yes" value="1" v-model="picked">
            <label for="yes">是</label>
          </div>
          <div class="dib">
            <input type="radio" id="no" value="0" v-model="picked">
            <label for="no">否</label>
          </div>
        </li>
        <li>
          <span>备注：</span>
          <textarea class="vt" v-model="remarks"></textarea>
        </li>
        <li>
          <span></span>
          <button type="submit" class="blue-button xl-btn-css">保存</button>
          <button type="button" class="blue-button xl-btn-css">取消</button>
        </li>
      </ul>
    </form>
  </div>
</template>
<script type="text/javascript">
export default {
  data() {
    return {
      roleName: '',
      picked: '',
      remarks: ''
    }
  },
  methods: {
    onSubmitClick() {
      if (!this.roleName) {
        this.$toasted.show('请输入角色名称')
      }
      if (!this.picked) {
        this.$toasted.show('请选择是否可用')
      }
      this.$http.post('/sys/role/update', {
        roleName: this.roleName,
        enable: this.picked,
        remark: this.remarks
      }).then(data => {
        if (data.data.httpCode === 200) {
          this.$toasted.show('添加成功')
          this.$router.push('/index/role-manage')
        } else {
          this.$toasted.show(data.data.msg)
        }
      }).catch(() => {
        this.$toasted.show('网络错误')
      })
    }
  }
}

</script>
<style type="text/css" scoped>
.container {
  margin-top: 20px;
}

.min-height {
  min-height: 507px;
}

.box-title a {
  color: #a5a5a5;
}

ul {
  padding: 0 0 70px 190px;
}

ul li {
  padding: 10px 0;
}

ul li span {
  width: 194px;
  display: inline-block;
  text-align: right;
  color: #666666;
  margin-right: 20px;
}

textarea {
  width: 350px;
  height: 140px;
  padding: 10px;
}

button {
  margin-right: 45px;
}

</style>
